// import dotenv from 'dotenv';
import web3 from './web3.js';
import fs from 'fs';
import path from 'path';

const contractName = 'RecordRegistry';

// console.log(`Loading ABI for ${contractName} from abis/${contractName}.json`);
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// 从contract-address.json读取地址
const addressPath = path.join(__dirname, 'contract-address.json');
const addresses = JSON.parse(fs.readFileSync(addressPath, 'utf8'));
const address = addresses[contractName];

const abiPath = path.join(__dirname, 'abis', `${contractName}.json`);
const abi = JSON.parse(fs.readFileSync(abiPath, 'utf8'));

// console.log(abi);

const recordRegistry = new web3.eth.Contract(abi, address);
export default recordRegistry;